/**
 * <copyright>
 * </copyright>
 *
 */
package org.xtext.example.mydsl.myDsl.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.xtext.example.mydsl.myDsl.MyDslPackage;
import org.xtext.example.mydsl.myDsl.T;
import org.xtext.example.mydsl.myDsl.T2;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>T2</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.xtext.example.mydsl.myDsl.impl.T2Impl#getP1 <em>P1</em>}</li>
 *   <li>{@link org.xtext.example.mydsl.myDsl.impl.T2Impl#getC1 <em>C1</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class T2Impl extends TImpl implements T2
{
  /**
   * The cached value of the '{@link #getP1() <em>P1</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getP1()
   * @generated
   * @ordered
   */
  protected T p1;

  /**
   * The cached value of the '{@link #getC1() <em>C1</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getC1()
   * @generated
   * @ordered
   */
  protected EList<T> c1;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected T2Impl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return MyDslPackage.Literals.T2;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public T getP1()
  {
    return p1;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetP1(T newP1, NotificationChain msgs)
  {
    T oldP1 = p1;
    p1 = newP1;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MyDslPackage.T2__P1, oldP1, newP1);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setP1(T newP1)
  {
    if (newP1 != p1)
    {
      NotificationChain msgs = null;
      if (p1 != null)
        msgs = ((InternalEObject)p1).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - MyDslPackage.T2__P1, null, msgs);
      if (newP1 != null)
        msgs = ((InternalEObject)newP1).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - MyDslPackage.T2__P1, null, msgs);
      msgs = basicSetP1(newP1, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, MyDslPackage.T2__P1, newP1, newP1));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<T> getC1()
  {
    if (c1 == null)
    {
      c1 = new EObjectContainmentEList<T>(T.class, this, MyDslPackage.T2__C1);
    }
    return c1;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case MyDslPackage.T2__P1:
        return basicSetP1(null, msgs);
      case MyDslPackage.T2__C1:
        return ((InternalEList<?>)getC1()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case MyDslPackage.T2__P1:
        return getP1();
      case MyDslPackage.T2__C1:
        return getC1();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case MyDslPackage.T2__P1:
        setP1((T)newValue);
        return;
      case MyDslPackage.T2__C1:
        getC1().clear();
        getC1().addAll((Collection<? extends T>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case MyDslPackage.T2__P1:
        setP1((T)null);
        return;
      case MyDslPackage.T2__C1:
        getC1().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case MyDslPackage.T2__P1:
        return p1 != null;
      case MyDslPackage.T2__C1:
        return c1 != null && !c1.isEmpty();
    }
    return super.eIsSet(featureID);
  }

} //T2Impl
